package com.trade.common.utils;

import java.text.CharacterIterator;
import java.text.StringCharacterIterator;

/**
 * 对手URL中回调参数过滤
 * @author  dsp
 * @date 创建时间：2015年11月21日 下午3:19:05
 * @version 1.0
 * @since jdk1.6
 */
public class UrlParamFilter {

	public static String HTMLEncode(String aText){
		
	     final StringBuilder result = new StringBuilder();
	     
	     final StringCharacterIterator iterator = new StringCharacterIterator(aText);
	     
	     char character =  iterator.current();
	     
	     while (character != CharacterIterator.DONE ){
	    	 
	       if (character == '<') {
	    	   
	         result.append("&lt;");
	         
	       }
	       else if (character == '>') {
	    	   
	         result.append("&gt;");
	         
	       }
	       else if (character == '&') {
	    	   
	         result.append("&amp;");
	         
	      }
	       else if (character == '\"') {
	    	   
	         result.append("&quot;");
	       }else if (character == '\r' ||character == '\n'){
	    	   
	       }else {
	         //the char is not a special one
	         //add it to the result as is
	         result.append(character);
	       }
	       character = iterator.next();
	     }
	     return result.toString();
	  }

}
